/**
*	插件：chat会话用
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

js.chat = {
	create:function(cans){
		var me = this;
		var defv = js.applyIf(cans,{
			loadci:0,
			minid:999999999,
			maxid:0,
			issend:1,
			ismobile:0,
			cnum:'',
			isnew:false,
			atid:0,
			atname:'',
			listdata:{},
			filedata:{},
			info:{}
		});
		for(var i in defv)this[i]=defv[i];
		var rand  = this.rand;

		this.init = function(){
			this.showobj 	= $('#viewcontent_'+rand+'');
			this.inputobj  	= $('#input_content_'+rand+'');
			this.inputobj.attr('bh', this.info.bh);
			$('#shomain_'+rand+'').click(function(){
				me.hideweidi();
			});
			importjs('copy');
			if(this.ismobile==0){
				this.inputobj.keydown(function(e){
					return me.onkeydown(e);
				});
				this.inputobj.contextmenu(function(e){
					me.inputright(this,e);
					return false;
				});
			}
			if(this.isnew && this.ismobile ==0){
				reim = opener.reim;
			}
			strformat.init();
			strformat.ismobile = this.ismobile;
			reim[this.info.bh]=this;
			this.objstr = 'reim.'+this.info.bh+'';
			this.load(false);
		}
		
		this.load=function(iref,isnew){
			if(this.loadbool)return;
			this.loadci++;
			var minid = 0,maxid='';
			if(iref)minid = this.minid;
			if(isnew)maxid = this.maxid;
			this.loadbool = true;
			js.ajax.get({
				url:'api/reim/data',
				cnum:this.cnum,
				data:{
					type:this.info.type,
					receid:this.info.id,
					loadci:this.loadci,
					minid:minid,
					maxid:maxid
				},
				onerror:function(ret){
					me.loadshowerr(ret);
				}
			},function(ret){
				me.loadshow(ret.data,iref,isnew);
			});
		}
		
		this.loadmore = function(o1){
			$(o1).html(js.show.ling(12));
			this.load(o1);
		}
		
		this.loadnew  = function(){
			this.load(false, true);
		}
		
		this.hideweidi = function(){
			$('font[temp=weidu'+rand+']').remove();
			reim.hidestotal(this.info.type, this.info.id);
		}
		
		this.loadshow=function(da,iref,isnew){
			this.loadbool = false;
			if(da.receinfo)this.receinfo = da.receinfo;
			if(da.sendinfo)this.sendinfo = da.sendinfo;
			
			if(da.servernow){
				js.servernow = da.servernow;
				js.getsplit();
			}
			var data = da.data,len = data.length,sarr=[];
			if(this.loadci==1){
				this.issend = da.issend;
				this.showobj.html('');
				if(this.ismobile==0){
					if(this.isnew){
						js.plugin.scrollbar(function(){
							$('#viewcontent_'+rand+'').perfectScrollbar();
						});
					}else{
						$('#viewcontent_'+rand+'').perfectScrollbar();
					}
				}
				if(this.issend==0 && da.showmsg)this.inputobj[0].disabled=true;
			}
			
			if(da.showmsg)this.addmsg(da.showmsg);
			if(this.loadci==1 && len==0){
				return;
			}
			if(isnew && len==0)return;
			var i,d,nr,rnd,cont,sid,lx,sbq,fd;
			if(iref){
				$(iref).parent().html('---------↑以上是新加载---------');
				sarr = data;
			}else{
				for(i=len-1; i>=0; i--)sarr.push(data[i]);
			}
			if(da.filearr)for(i=0;i<da.filearr.length;i++)this.filedata[da.filearr[i].fileid]=da.filearr[i];
			for(i=0;i<len;i++){
				d  	 = sarr[i];
				sid  = parseFloat(d.id);
				if(sid<this.minid)this.minid=sid;
				if(sid>this.maxid)this.maxid=sid;
				rnd	 = 'mess_'+d.id+'';
				if(this.listdata[rnd])continue;
				sbq	 = '';
				if(isnew)sbq	 = '<font temp="weidu'+rand+'" color=red>●</font> ';
				lx 	 = 'left';
				if(d.sendid==this.sendinfo.id)lx='right';
				d.lx = lx;
				this.listdata[rnd] = d;
				cont = jm.base64decode(d.cont);
				if(d.fileid>0){
					fd = this.filedata[d.fileid];
					if(fd)cont = strformat.contshozt(fd);
				}
				nr   = strformat.showqp(lx,sbq+d.sendname,d.optdt,cont,'', d.sendface,rnd);
				this.addcont(nr, iref);
				$('#qipaocont_'+rnd+'').contextmenu(function(e){
					me.contright(this,e);
					return false;
				});
			}
			
			if(isnew){
				this.scrollboot();
			}else{
				if(da.systotal>0){
					this.addmsg('<a class="fontsize12" onclick="'+this.objstr+'.loadmore(this)"><i class="icon-time"></i> 还有'+da.systotal+'条点我查看更多</a>', true);
				}else{
					this.addmsg('没有更多了', true);
				}
				if(this.loadci==1 && len>0){
					this.addmsg('---------↑以上是历史记录---------');
					this.scrollboot();
				}
			}
		}
		
		this.contright = function(o1,evt){
			var o = $(o1),rnd=o.attr('rand');
			var d = this.listdata[rnd],isch=false;
			var da=[{name:'复制此消息',lx:0},{name:'删除',lx:1,color:'#D9534F'}];
			if(d.lx=='right' && reim.cehui && !d.cehui){
				var cehui = parseFloat(reim.cehui) * 60;
				var t1 = js.now('time', d.optdt),t2 = js.now('time', js.serverdt());
				var t3 = (t2-t1)*0.001;
				if(t3<cehui)isch = true;
			}
			if(isch)da.push({name:'撤回',lx:5});
			if(this.info.type==1)da.push({name:'@TA',lx:3});
			importjs('menu','create', {
				obj:o,data:da,width:120,
				onclick:function(d1){
					me.contrightclick(d1.lx, d, rnd);
				},
				showXY:{
					left:evt.clientX+3,
					top:evt.clientY+3
				}
			});
		}
		
		this.contrightclick = function(lx, d, rnd){
			if(lx==1){
				$('#ltcont_'+rnd+'').remove();
				js.ajax.get({
					url:xcy.getacturl('immess','delmess'),
					cnum:this.cnum,
					data:{
						type:this.info.type,
						receid:this.info.id,
						id:d.id
					}
				},function(ret){
					reim.rechehui(d.id);
				});
			}
			if(lx==0){
				var cont =jm.base64decode(d.cont);
				if(!cont)cont = $('#qipaocont_'+rnd+'').text();
				if(cont)js.copy.set(cont);
			}
			if(lx==5){
				d.cehui = true;
				var o = $('#qipaocont_'+rnd+'');
				o.html(''+js.show.ling(16)+'撤回中...');
				js.ajax.get({
					url:'api/reim/cehui',
					cnum:this.cnum,
					data:{
						type:this.info.type,
						receid:this.info.id,
						id:d.id
					},
					onerror:function(ret){
						o.html('撤回失败');
					},
				},function(ret){
					$('#ltcont_'+rnd+'').remove();
					js.msg('success','已撤回');
					reim.rechehui(ret.data.id);
				});
			}
			if(lx==3){
				this.sendatid(d.sendid, d.sendname);
			}
		}
		
		this.sendatid = function(id1,na1){
			this.atid 	= id1;
			this.atname = na1;
			var s = '<font color="'+maincolor+'">当前：@'+na1+'</font>';
			if(id1==0){
				s='';
				if(!na1)js.msg('success','取消了@TA');
			}
			$('#atspan_'+this.rand+'').html(s);
			if(s)this.inputobj.focus();
		}
		
		this.inputright=function(o,evt){
			//alert(getSelection());
			this.selectionStart = o.selectionStart;
			this.selectionEnd   = o.selectionEnd;
			var sel = o.value.substr(o.selectionStart,o.selectionEnd-o.selectionStart);
			this.selectValue	= sel;
			var d = [];
			d.push({name:'复制',lx:1});
			d.push({name:'剪切',lx:2});
			if(nwjs){d.push({'name':'粘贴',lx:0});}
			d.push({name:'清空',lx:4,disabled:(o.value)?false:true});
			if(!sel){
				d[0].disabled = true;
				d[1].disabled = true;
			}
			importjs('menu','create', {
				obj:$(o),data:d,width:120,
				onclick:function(d1){
					me.inputrightclick(d1);
				},
				showXY:{
					left:evt.clientX+3,
					top:evt.clientY+3
				}
			});
		};
		
		this.inputrightclick=function(d){
			if(d.lx==0){
				var snr  = js.nwjs.clipobj().get('text'),nr = this.inputobj.val();
				if(snr){
					var s1 = nr.substr(0,this.selectionStart)+snr+nr.substr(this.selectionEnd);
					this.inputobj.val(s1).focus();
				}
			}
			if(d.lx==1){
				js.copy.set(this.selectValue,true);
			}
			if(d.lx==2){
				js.copy.set(this.selectValue,true);
				var nr = this.inputobj.val();
				var s1 = nr.substr(0,this.selectionStart)+nr.substr(this.selectionEnd);
				this.inputobj.val(s1).focus();
			}
			if(d.lx==4)this.inputobj.val('').focus();
		}
		
		this.loadshowerr = function(ret){
			this.loadbool = false;
		}
		
		this.sendcont=function(){
			if(this.issend==0)return;
			var cont = this.inputobj.val();
			js.show.hide();
			if(!cont){js.show.error('无输入内容');return;}
			this.inputobj.val('');
			cont	 = cont.replace(/</gi,'&lt;').replace(/>/gi,'&gt;').replace(/\n/gi,'<br>');
			
			var nuid= js.now('time'),optdt = js.serverdt(),ats='';
			if(optdt==this.nowoptdt){
				js.show.error('消息发太快了');
				return;
			}
			if(this.atid>0 && this.atname)ats='<font class="zhu">@'+this.atname+'</font> ';
			this.nowoptdt = optdt;
			var nr   = strformat.showqp('right',this.sendinfo.name,optdt,ats+cont, nuid, this.sendinfo.face,nuid);
			this.addcont(nr);
			this.scrollboot();
			this.sendconts(cont,nuid,optdt,'0');
			this.inputobj.focus();
		}
		
		this.sendconts=function(nr,nuid,optdt, fid, fun, ods){
			this.sendbool = true;
			if(this.atid>0 && this.atname)nr ='<font class="zhu">@'+this.atname+'</font> '+nr+'';
			var cont = jm.base64encode(nr);
			this.hideweidi();
			var ds = {
				cont:cont,
				fileid:fid,
				nuid:nuid,
				atid:this.atid,
				optdt:optdt
			}
			if(ods)for(var i in ods)ds[i] = ods[i];
			js.ajax.post({
				url:'api/reim/submit',
				cnum:this.cnum,
				urlda:{
					type:this.info.type,
					receid:this.info.id
				},
				data:ds,
				onerror:function(ret){
					me.senderror(ret, nuid);
				}
			},function(ret){
				me.sendsuccess(ret.data, ds);
				if(fun)fun();
			});
		}
		
		this.sendsuccess=function(da, ds){
			this.sendbool = false;
			this.sendatid(0,'qx');
			var nuid = da.nuid;
			if(nuid)$('#'+nuid+'').remove();
			var sid  = parseFloat(da.id);
			if(sid>this.maxid)this.maxid=sid;
			da.lx 	= 'right';
			da.cont	= ds.cont;
			da.sendid   = this.sendinfo.id;
			da.sendname = this.sendinfo.name;
			da.sendface = this.sendinfo.face;
			this.listdata['mess_'+da.id] = da;
			this.listdata[nuid] = da;
			$('#qipaocont_'+nuid+'').contextmenu(function(e){
				me.contright(this,e);
				return false;
			});
			var s1 = '';
			if(this.info.type=='1')s1=jm.base64encode(''+this.sendinfo.name+':');
			reim.historyfirst({
				lastcont:s1+da.cont,
				optdt:da.optdt,
				sendid:this.info.id,
				type:this.info.type,
				lastid:da.id,
				stotal:0,
				sendname:this.info.name,
				sendface:this.info.face,
				bqname:this.info.bqname,
				bqcolor:this.info.bqcolor
			});
		}
		
		this.senderror = function(ret, nuid){
			this.sendbool = false;
			js.show.hide();
			$('#'+nuid+'').html('<font color="red"><i class="icon-remove-sign"></i></font>&nbsp;');
			this.addmsg(ret.msg);
			this.scrollboot();
		}
		
		//滚动条到最下面
		this.scrollboot=function(){
			var sid = 'viewcontent_'+rand+'';
			if(get(sid))this.showobj.animate({scrollTop:get(sid).scrollHeight},100);
			sid = 'downjd_'+this.num+'';
			if(get(sid))$('#'+sid+'').hide();
		};
		
		this.addmsg=function(msg, bo){
			if(bo){
				this.showobj.prepend('<div class="showblanks">'+msg+'</div>');	
			}else{
				this.showobj.append('<div class="showblanks">'+msg+'</div>');	
			}
		};
		
		this.addcont=function(cont, isbf){
			var o	= this.showobj;
			if(isbf){o.prepend(cont);}else{o.append(cont);}
			//clearTimeout(this.scrolltime);
			//if(!isbf)this.scrolltime = setTimeout(function(){me.scrollboot();}, 50);
		};
		
		this.addinput=function(s){
			var val = this.inputobj.val()+s;
			this.inputobj.val(val).focus();
		};
		
		this.closechat = function(){
			reim.closetabs(this.info.bh);
		}
		
		this.onkeydown=function(e){
			var code = e.keyCode,kj = js.getoption('sendkuijie');
			if(code==13 && e.shiftKey){
				this.addinput('\n')
				return false;
			}
			if(code==13 && !e.ctrlKey && kj!='1'){
				this.sendcont();
				return false;
			}
			if(e.altKey && code==83){
				this.sendcont();
				return false;
			}
			if(e.altKey && code==67){
				this.closechat();
				return false;
			}
			if(e.ctrlKey && code==13){
				if(kj=='1'){this.sendcont();}else{this.addinput('\n');}
				return false;
			}
			return true;
		};
		
		//收到了消息
		this.onmessage = function(d){
			if(!get('viewcontent_'+rand+''))return;
			var xtype = d.xtype;
			if(xtype=='send'){
				this.loadnew();
			}
			if(xtype=='chehui'){
			}
		}
		
		this.onshow = function(){
			this.hideweidi();
		}
		
		this.sendtools = function(o1,evt){
			var o    = $(evt.target).parent();
			var tools= o.attr('tools');
			if(!tools)tools= $(evt.target).attr('tools');;
			if(!tools)return;
			if(this.issend==0 && tools!='group'){js.show.error('无法操作');return;}
			this.sendtoolss(tools,o);
		}
		
		this.sendtoolss= function(lx,o){
			if(lx=='emts'){
				this.getemts(o);
			}
			if(lx=='exit'){
				js.modal.confirm({
					msg:'确定要退出群“'+this.info.name+'”吗？'
				},function(jg){
					if(jg=='yes')me.groupexit();
				});
			}
			if(lx=='files'){
				importjs('rockfile','uploafile',{
					name:'发送多文件',
					uptype:'',
					cnum:this.cnum,
					oncallback:function(farr){
						me.sendfileall(farr);
					}
				});
			}
			if(lx=='file'){
				if(reim.fileobj){
					js.rockfile.cnum = this.cnum;
					reim.fileobj.click({
						uptype:'',
						bh:this.info.bh,
						nuid:js.now('time')
					});
				}
			}
			if(lx=='crop'){
				js.show.success('请使用第三方快捷截图在到文本框里Ctrl+V');
			}
			if(lx=='star'){
				js.show.error('待开发');
			}
			if(lx=='add'){
				importjs('changeuser','create',{
					changetype:'usercheck',
					cnum:this.cnum,
					title:'邀请人员',
					onselect:function(san,sid){
						if(sid)me.savegroupuser(sid);
					}
				});
			}
			if(lx=='group'){
				reim.addtabs('tchatinfo_'+this.info.bh+'','reim/chatinfo',{
					cnum:this.cnum,
					bh:this.info.bh,
					id:this.info.id,
					type:this.info.type,
					scroll:true,
					name:this.info.name
				});
			}
			if(lx=='at')this.sendatid(0,'');
		}
		
		this.savegroupuser = function(sid, gid, type){
			js.ajax.post({
				loading:'邀请中...',
				url:xcy.getacturl('imgroup','savegroupuser'),
				cnum:this.cnum,
				loadsuccess:'邀请成功',
				data:{
					sid:sid,
					gid:this.info.id,
					type:this.info.type
				}
			},function(ret){
				me.showreceinfo(ret.data);
			});
		}
	
		
		this.showreceinfo=function(d){
			if(!d){
				d = this.receinfo;
				d.ushu = parseFloat(d.ushu)-1;
			}
			this.receinfo = d;
			this.optobj.showtitle(d);
			reim.grouparr[d.id]= d;
		};
		
		this.groupexit = function(){
			this.issend = 0;
			this.inputobj[0].disabled=true;
			js.ajax.get({
				url:'api/reim/groupexit',
				cnum:this.cnum,
				loading:'退出中..',
				loadsuccess:'已退出',
				urlda:{
					type:this.info.type,
					gid:this.info.id,
					sid:this.sendinfo.id
				}
			},function(ret){
				me.showreceinfo(false);
			});
		}
		
		//连续发送文件
		this.sendfileall = function(farr){
			var len = farr.length,i;
			this.tempfarr = farr;
			this.tempatid = ''+this.atid+'';
			this.tempatna = ''+this.atname+'';
			this.sendfilestart(0);
		}
		this.sendfilestart = function(xu){
			var len = this.tempfarr.length;
			if(xu==len){
				js.show.success('已发送文件'+len+'个');
				return;
			}
			this.atid 	= this.tempatid;
			this.atname = this.tempatna;
			js.loading('发送中('+this.tempfarr.length+'/'+(xu+1)+')..');
			var f  = this.tempfarr[xu];
			var cont = strformat.contshozt(f);
			var nuid = js.now('time'),optdt = js.serverdt();
			var nr   = strformat.showqp('right',this.sendinfo.name,optdt,cont, nuid, this.sendinfo.face,nuid);
			this.addcont(nr);
			this.scrollboot();
			nr 	= '['+f.filename+' '+f.filesizecn+']';
			if(js.isimg(js.fileext))nr='[图片 '+f.filesizecn+']';
			this.filedata[f.id] = f;
			var nopush = '1';
			if(len==xu+1)nopush='';
			this.sendconts(nr,nuid,optdt, f.id, function(){
				setTimeout(function(){me.sendfilestart(xu+1);},1000);
			},{
				'nopush':nopush
			});
		}
		
		this.sendfileshow = function(f){
			var ad = strformat.showupfile(f);
			this.addcont(ad.cont);
			this.scrollboot();
		}
		
		this.upprogresss = function(f,per){
			strformat.upprogresss(per,f.nuid);
		}
		
		this.sendfileok = function(f,da){
			this.filedata[da.id] = da;
			var nr = strformat.upsuccess(da,f.nuid);
			var optdt = js.serverdt();
			this.sendconts(nr,f.nuid,optdt, da.id);
		}
		
		this.getemts=function(o){
			reim.nowbh = this.info.bh;
			if(!get('aemtsdiv')){
				var wei = 410,gw=10,ove='hidden';
				if(this.ismobile==1){
					wei = winWb()-25;
					gw = 8;ove='auto';
				}
				var s = '<div id="aemtsdiv" style="width:'+wei+'px;height:200px;overflow:'+ove+';border:0.5px #cccccc solid;background:white;box-shadow:0px 0px 5px rgba(0,0,0,0.3);left:3px;top:5px;position:absolute;display:none;z-index:6">';
				s+='<div style="padding:5px">';
				s+=this.getemtsbq('qq',0, 104, gw, 24);
				s+='</div>';
				s+='</div>';
				$('body').append(s);
				if(this.ismobile==0)$('#aemtsdiv').perfectScrollbar();
				js.bodyclick.addbody('emts','hide','aemtsdiv');
			}
			var o1  = $('#aemtsdiv');
			o1.toggle();
			var off = o.offset();
			o1.css({'top':''+(off.top-205)+'px','left':''+(off.left)+'px'});
		}
		
		this.getemtsbq=function(wj, oi1,oi2, fzd, dx){
			var i,oi=0,j1 = js.float(100/fzd);
			var s = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
			for(i=oi1; i<=oi2; i++){
				oi++;
				s+='<td class="toolsspan" width="'+j1+'%" title="'+strformat.emotsarr[i+1]+'" align="center"><img onclick="reim.backemts(\''+strformat.emotsarr[i+1]+'\')" src="'+strformat.emotspath+'images/im/emots/'+wj+'/'+i+'.gif" width="'+dx+'" height="'+dx+'"></td>';
				if(oi % fzd==0)s+='</tr><tr>';
			}
			s+='</tr></table>';
			return s;
		}
		
		this.backemts = function(bq){
			$('#aemtsdiv').hide();
			this.addinput(bq);
		}
		
		//粘贴图片
		this.readclipshow = function(snr){
			var nuid = js.now('time');
			var fa 	= strformat.showupfile({
				face:this.sendinfo.face,
				sendname:this.sendinfo.name,
				nuid:nuid,
				bh:this.info.bh
			}, snr);
			var cont= fa.cont;
			this.addcont(cont);	
			this.scrollboot();
		}
		
		this.init();
	}
}


var touchobj=false;
var strformat = {
	sendcodearr:{},
	sendcuxo:0,
	ismobile:0,
	emotsstr:',[微笑],[撇嘴],[色],[发呆],[得意],[流泪],[害羞],[闭嘴],[睡],[大哭],[尴尬],[发怒],[调皮],[呲牙],[惊讶],[难过],[酷],[冷汗],[抓狂],[吐],[偷笑],[愉快],[白眼],[傲慢],[饥饿],[困],[恐惧],[流汗],[憨笑],[悠闲],[奋斗],[咒骂],[疑问],[嘘],[晕],[疯了],[衰],[骷髅],[敲打],[再见],[擦汗],[抠鼻],[鼓掌],[糗大了],[坏笑],[左哼哼],[右哼哼],[哈欠],[鄙视],[委屈],[快哭了],[阴险],[亲亲],[吓],[可怜],[菜刀],[西瓜],[啤酒],[篮球],[乒乓],[咖啡],[饭],[猪头],[玫瑰],[凋谢],[嘴唇],[爱心],[心碎],[蛋糕],[闪电],[炸弹],[刀],[足球],[瓢虫],[便便],[月亮],[太阳],[礼物],[拥抱],[强],[弱],[握手],[胜利],[抱拳],[勾引],[拳头],[差劲],[爱你],[NO],[OK],[爱情],[飞吻],[跳跳],[发抖],[怄火],[转圈],[磕头],[回头],[跳绳],[投降],[激动],[街舞],[献吻],[左太极],[右太极]',
	emotspath:'https://file.rockoa.com/',
	openurl:function(dz){
		if(this.ismobile==0){
			window.open(dz);
		}else{
			js.location(dz);
		}
	},
	urlpipei:function(str){
		urlpipeiarr = [];
		var strv = this.urlpipeiss(str,'http://');
		strv = this.urlpipeiss(strv,'https://');
		var i,len = urlpipeiarr.length,sv;
		if(len>0)for(i=0;i<len;i++){
			sv   = urlpipeiarr[i];
			strv = strv.replace('{URL'+i+'}','<a onclick="return strformat.openurl(\''+sv+'\')" href="javascript:;">'+sv+'</a>');
		}
		return strv;
	},
	urlpipeiss:function(str,gz){
		var s1 = str.toLowerCase();
		var xu = s1.indexOf(gz);
		if(xu==-1)return str;
		var len = gz.length,zlen = s1.length;
		var jg = 0,s2,i,ym,tsx=',./?&=#@*()_-+;!|:%',cd;
		for(i=0;i<zlen-len;i++){
			s2 = s1.substr(xu+len+i,1);
			if(!s2 || (tsx.indexOf(s2)==-1 && !/[a-zA-Z0-9]{1,}/.test(s2)))break;
			jg++;
		}
		ym = str.substr(xu,len+jg);
		cd = urlpipeiarr.push(ym);
		var strv= str.replace(ym,'{URL'+(cd-1)+'}');
		return this.urlpipeiss(strv,gz);
	},
	strcont:function(nr){
		var str = unescape(nr),patt1,emu,i,st1,oi;
		
		if(str.indexOf('<img')==-1)str = this.urlpipei(str);
	
		patt1	= new RegExp("\\[(.*?)\\](.*?)", 'gi');
		emu		= str.match(patt1);
		if(emu!=null){
			for(i=0;i<emu.length; i++){
				st1=emu[i];
				oi=this.emotsarrss[st1];
				if(oi)str	= str.replace(st1, '<img align="absmiddle" height="24" width="24" src="'+this.emotspath+'images/im/emots/qq/'+(oi-1)+'.gif">');
			}
		}
		str	= str.replace(/\n/gi, '<br>');
		return str;
	},
	showdt:function(sj){
		if(!sj)sj='';
		var s='';
		sja=sj.split(' ');
		if(sj.indexOf(this.dt)==0){
			s=sja[1];
		}else{
			s=sj.substr(5,11);
		}
		return s;
	},
	showqp:function(type,name,dt,cont,nuid, fase,rnd,bqname,bqcor){
		var str = this.strcont(cont);
		if(!rnd)rnd=js.getrand();
		var nr	= '',bqs='';
		if(bqname && bqcor)bqs='<font style="background:'+bqcor+';font-size:10px;margin-right:2px;color:white;padding:1px 2px;border-radius:2px" >'+bqname+'</font>';
		this.showqpid = 'ltcont_'+rnd+'';
		nr+='<div id="'+this.showqpid+'" class="ltcont">';
		nr+='	<div class="qipao" align="'+type+'">';
		nr+='		<div class="dt" style="padding-'+type+':65px">'+bqs+'<font id="ltname_'+rnd+'">'+name+'</font>('+this.showdt(dt)+')</div>';
		
		nr+='		<table border="0" cellspacing="0" cellpadding="0">';
		
		nr+='		<tr valign="top">';
		if(type == 'left'){
			nr+='			<td width="50" align="center"><img src="'+getface(fase)+'" onclick="js.viewimg(this)" class="qipaoface" width="40" height="40"></td>';
			nr+='			<td><div class="qipao'+type+'"></div></td>';
		}else{
			nr+='			<td width="30" align="right" valign="middle">';
			if(nuid)nr+='<span title="发送中..." id="'+nuid+'">'+js.show.ling(16)+'&nbsp;</span>';
			nr+='			</td>';
		}
		
		nr+='			<td>';
		nr+='			<div ontouchstart="touchobj=this" id="qipaocont_'+rnd+'" rand="'+rnd+'" class="qipaocont qipaocont'+type+'">'+str+'</div>';
		nr+='			</td>';
		
		if(type == 'right'){
			nr+='			<td><div class="qipao'+type+'"></div></td>';
			nr+='			<td width="50" align="center"><img src="'+getface(fase)+'" onclick="js.viewimg(this)" class="qipaoface" width="40" height="40"></td>';
		}else{
			nr+='			<td width="30"></td>';
		}
		
		nr+='		</tr></table>';
		nr+='	</div>';
		nr+='</div>';
		return nr;
	},
	clickface:function(){
		
	},
	showupfile:function(f, snr){
		var nuid= f.nuid,optdt = js.serverdt(),nr='';
		if(!nuid)return;
		nr = '<div id="showve_'+nuid+'">';
		if(f && f.filename){
			if(f.isimg){
				var src = 'images/noimg.jpg';
				if(f.thumbpath)src = ''+f.thumbpath+'';
				if(f.imgviewurl)src = f.imgviewurl;
				nr+='<div><img width="150" onclick="strformat.clickimg(this)" id="imgview_'+nuid+'" src="'+src+'"><br>'+f.filesizecn+'</div>';
			}else{
				nr+= '<table><tr><td><div class="qipaofile">'+f.fileext.toUpperCase()+'</div></td><td>'+f.filename+'<br><span style="font-size:12px;color:#888888">('+f.filesizecn+')</span></td></tr></table>';
			}
		}
		if(snr){
			nr+= '<div><img src="'+snr+'" onclick="strformat.clickimg(this)" id="jietuimg_'+nuid+'" width="150"></div>';
			nr+= '<div><a onclick="reim.upbase64(\''+nuid+'\',\''+f.bh+'\')" href="javascript:;">[发送截图]</a>';
		}
		nr+= '<div class="progresscls"><div id="progresscls_'+nuid+'" class="progressclssse"></div><div class="progressclstext" id="progresstext_'+nuid+'">0%</div></div>';
		nr+= '<div id="progcanter_'+nuid+'"><a href="javascript:;" onclick="strformat.cancelup(\''+nuid+'\')">取消</a></div>';
		nr+= '</div>';
		this.nuidup_tep = nuid;
		var nas = f.sendname;
		if(!nas)nas='我';
		var cont= this.showqp('right',nas,optdt, nr, nuid, f.face, nuid,f.bqname,f.bqcolor);
		return {'cont':cont,optdt:optdt,nuid:nuid};
	},
	upprogresss:function(per, nuid){
		if(!nuid)nuid=this.nuidup_tep;
		$('#progresscls_'+nuid+'').css('width',''+per+'%');
		$('#progresstext_'+nuid+'').html(''+per+'%');
		if(per==100)$('#progcanter_'+nuid+'').remove();
	},
	upsuccess:function(f,nuid){
		if(!nuid)nuid=this.nuidup_tep;
		this.upprogresss(100, nuid);
		$('#progresstext_'+nuid+'').html('上传成功');
		var contss;
		if(js.isimg(f.fileext)){
			contss = '[图片 '+f.filesizecn+']';
		}else{
			contss = '['+f.filename+' '+f.filesizecn+']';
		}
		var s = this.contshozt(f);
		$('#showve_'+nuid+'').html(s);
		return contss;
	},
	uperror:function(nuid){
		if(!nuid)nuid=this.nuidup_tep;
		$('#progresstext_'+nuid+'').html('<font color=red>上传失败</font>');
		$('#progcanter_'+nuid+'').remove();
	},
	cancelup:function(nuid){
		if(!nuid)nuid=this.nuidup_tep;
		try{if(this.upobj)this.upobj.abort();}catch(e){}
		$('#ltcont_'+nuid+'').remove();
	},
	openimg:function(src){
		var img = src;
		if(src.indexOf('thumb')>0){
			var ext = src.substr(src.lastIndexOf('.')+1);
			img = src.substr(0,src.lastIndexOf('_'))+'.'+ext;
		}
		js.open(img);
	},
	emotsarrss:{},
	init:function(){
		if(this.initbo)return;
		var a = this.emotsstr.split(',');
		this.emotsarr=a;
		var len = a.length,i;
		for(i=1;i<len;i++){
			this.emotsarrss[a[i]]=i;
		}
		this.dt=js.now();
		this.initbo = true;
	},
	contshozt:function(d, lj){
		var s='',sttr,src;
		if(!d)return s;
		if(!d.fileid)d.fileid=d.id;
		if(js.isimg(d.fileext)){
			sttr='';src = d.thumbpath;
			if(d.filesizecn)sttr='filesizecn="'+d.filesizecn+'"';
			if(src){
				var kzm = src.substr(-3).toLowerCase();
				if(kzm=='gif' && js.getoption(md5(src))=='true')src = src.replace('_s.','.');
				s='<img src="'+src+'" '+sttr+' style="max-width:250px" onclick="strformat.clickimg(this)">';
			}else{
				if(d.width){
					if(d.width>150)sttr+=' width="150"';
				}else{
					sttr+=' width="150"';
				}
				s='<img src="'+d.filepath+'" onclick="strformat.clickimg(this)" '+sttr+'>';
			}
		}else if(d.fileext=='amr'){
			s+='<i class="icon-volume-up"></i> '+(parseInt(d.filesize/1000))+'"';
			s+='&nbsp;<a href="javascript:;" style="font-size:12px" onclick="strformat.clickfile(\''+d.filenum+'\',1)">下载</a>';
		}else{
			s='<table><tr><td><div class="qipaofile">'+d.fileext.toUpperCase()+'</div></td><td>'+d.filename+'<br><span style="font-size:12px;color:#888888">('+d.filesizecn+')&nbsp;&nbsp;<a href="javascript:;" onclick="strformat.clickfile(\''+d.filenum+'\',1)">下载</a>&nbsp;&nbsp;<a href="javascript:;" onclick="strformat.clickfile(\''+d.filenum+'\',0)">预览</a></span></td></tr></table>';
		}
		return s;
	},
	clickfile:function(fid,lx){
		js.rockfile.view(fid,lx);
	},
	clickimg:function(o){
		js.viewimg(o);
	}
}